using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QFramework;
using UnityEngine.InputSystem;
using M13.Base;
namespace M13.GameSystem
{
    public interface IInputCtrlSystem : ISystem
    {
        public float AxisXInput { get; set; }
        public float AxisYInput { get; set; }
        public float WheelInput { get; set; }
        public int NumInput { get; set; }
        public float MotionSwitchInput { get; set; }
        public float CameraLeftRotInput { get; set; }
        public float CameraRightRotInput { get; set; }
        public float InventoryInput { get; set; }
        public float Execute0Input { get; set; }
        public float Execute1Input { get; set; }
        public float DebuginfoInput { get; set; }
        public float GameMenuInput { get; set; }
        public Vector2 CursorPosInput { get; set; }
        public void Enable();
        public void Disable();
    }

    public class InputCtrlSystem : AbstractSystem, IInputCtrlSystem, InputCtrl.IGameActions, InputCtrl.IUIActions
    {
        private InputCtrl _mInput = new InputCtrl();

        AxisInput _asixInput;
        ScrollWheel _scrollWheel;
        NumKey _numKey;
        DebugInfoBroadButton _debugInfoBroadButton;
        InventoryActionButton _inventoryActionButton;
        Evecute0Button _evecute0Button;
        Evecute1Button _evecute1Button;
        CameraLeftRotButton _cameraLeftRotButton;
        CameraRightRotButton _cameraRightRotButton;
        MotionSwitchButton _motionSwitchButton;
        GameMenuButton _gameMenuButton;

        #region -------��----------------
        /// <summary>
        /// �����ƶ�����
        /// </summary>
        public float AxisXInput { get; set; }
        /// <summary>
        /// �����ƶ�����
        /// </summary>
        public float AxisYInput { get; set; }
        /// <summary>
        /// ��������
        /// </summary>
        public float WheelInput { get; set; }
        /// <summary>
        /// ��������
        /// </summary>
        public int NumInput { get; set; }
        /// <summary>
        ///  ��������
        /// </summary>
        public float MotionSwitchInput { get; set; }
        /// <summary>
        /// �����ת����
        /// </summary>
        public float CameraLeftRotInput { get; set; }
        /// <summary>
        /// �����ת����
        /// </summary>
        public float CameraRightRotInput { get; set; }
        /// <summary>
        /// �򿪱�������
        /// </summary>
        public float InventoryInput { get; set; }
        /// <summary>
        /// �����Ļλ������
        /// </summary>
        public Vector2 CursorPosInput { get; set; }
        /// <summary>
        /// ִ��һ
        /// </summary>
        public float Execute0Input { get; set; }
        /// <summary>
        /// ִ�ж�
        /// </summary>
        public float Execute1Input { get; set; }
        /// <summary>
        /// debug��忪��
        /// </summary>
        public float DebuginfoInput { get; set; }
        public float GameMenuInput { get; set; }
        #endregion
        protected override void OnInit()
        {
            _mInput.Game.SetCallbacks(this);
            _mInput.Game.Enable();
            _mInput.UI.SetCallbacks(this);
            _mInput.UI.Enable();
        }
        void IInputCtrlSystem.Enable()
        {
            _mInput.Game.Enable();
            _mInput.UI.Enable();
        }
        void IInputCtrlSystem.Disable()
        {
            _mInput.Game.Disable();
            _mInput.UI.Disable();
        }

        #region -----------------GAME---------------------------------------------

        /// <summary>
        /// ��ά��������
        /// </summary>
        /// <param name="context"></param>
        public void OnAxis(InputAction.CallbackContext context)
        {
            if (context.performed)
            {
                Vector2 vector2 = context.ReadValue<Vector2>();
                _asixInput.axisXInput = AxisXInput = vector2.x;
                _asixInput.axisYInput = AxisYInput = vector2.y;
                this.SendEvent(_asixInput);
            }
            else
            {
                Vector2 vector2 = context.ReadValue<Vector2>();
                _asixInput.axisXInput = AxisXInput = 0f;
                _asixInput.axisYInput = AxisYInput = 0f;
                this.SendEvent(_asixInput);
            }
        }
        /// <summary>
        /// ������
        /// </summary>
        /// <param name="context"></param>
        public void OnWheel(InputAction.CallbackContext context)
        {
            if (context.started)
            {
                _scrollWheel.wheelInput = WheelInput = Mathf.Clamp(context.action.ReadValue<float>(), -1f, 1f);
                this.SendEvent(_scrollWheel);
            }
        }
        /// <summary>
        /// ��������ּ�
        /// </summary>
        /// <param name="context"></param>
        public void OnNum(InputAction.CallbackContext context)
        {
            if (context.performed)
            {
                NumInput = _numKey.numInput = int.Parse(context.control.path.Remove(0, 10));
                this.SendEvent(_numKey);
            }
        }
        /// <summary>
        /// �ƶ�״̬�л�
        /// </summary>
        /// <param name="context"></param>
        public void OnMotionSwitch(InputAction.CallbackContext context)
        {
            if (context.started)
            {
                MotionSwitchInput = _motionSwitchButton.motionSwitchInput = 1f;
                this.SendEvent(_motionSwitchButton);
            }
            if (context.canceled)
            {
                MotionSwitchInput = _motionSwitchButton.motionSwitchInput = 0f;
                this.SendEvent(_motionSwitchButton);
            }
        }
        /// <summary>
        /// �����ת
        /// </summary>
        /// <param name="context"></param>
        public void OnCameraLeftRot(InputAction.CallbackContext context)
        {
            if (context.started)
            {
                CameraLeftRotInput = _cameraLeftRotButton.cameraLeftRotInput = 1f;
                this.SendEvent(_cameraLeftRotButton);
            }
            if (context.canceled)
            {
                CameraLeftRotInput = _cameraLeftRotButton.cameraLeftRotInput = 0f;
                this.SendEvent(_cameraLeftRotButton);
            }
        }
        /// <summary>
        /// �����ת
        /// </summary>
        /// <param name="context"></param>
        public void OnCameraRightRot(InputAction.CallbackContext context)
        {
            if (context.started)
            {
                CameraRightRotInput = _cameraRightRotButton.cameraRightRotInput = 1f;
                this.SendEvent(_cameraRightRotButton);
            }
            if (context.canceled)
            {
                CameraRightRotInput = _cameraRightRotButton.cameraRightRotInput = 0f;
                this.SendEvent(_cameraRightRotButton);
            }

        }
        /// <summary>
        /// �������Ļ����
        /// </summary>
        /// <param name="context"></param>
        public void OnMousePos(InputAction.CallbackContext context)
        {
            CursorPosInput = context.ReadValue<Vector2>();
        }
        /// <summary>
        /// ִ��0�����Ϊ���
        /// </summary>
        /// <param name="context"></param>
        public void OnExectue0(InputAction.CallbackContext context)
        {
            if (context.started)
            {
                Execute0Input = _evecute0Button.execute0Input = 1f;
                this.SendEvent(_evecute0Button);
            }
            if (context.canceled)
            {
                Execute0Input = _evecute0Button.execute0Input = 0f;
                this.SendEvent(_evecute0Button);
            }
        }
        /// <summary>
        /// ִ��1�����Ϊ�Ҽ�
        /// </summary>
        /// <param name="context"></param>
        public void OnExectue1(InputAction.CallbackContext context)
        {
            if (context.started)
            {
                Execute1Input = _evecute1Button.execute1Input = 1f;
                this.SendEvent(_evecute1Button);
            }
            if (context.canceled)
            {
                Execute1Input = _evecute1Button.execute1Input = 0f;
                this.SendEvent(_evecute1Button);
            }
        }
        /// <summary>
        /// ��������
        /// </summary>
        /// <param name="context"></param>
        public void OnInventoryAction(InputAction.CallbackContext context)
        {
            if (context.started)
            {
                InventoryInput = _inventoryActionButton.inventoryInput = 1f;
                this.SendEvent(_inventoryActionButton);
            }
            if (context.canceled)
            {
                InventoryInput = _inventoryActionButton.inventoryInput = 0f;
                this.SendEvent(_inventoryActionButton);
            }
        }
        #endregion


        #region -----------------UI------------------------------------------------
        /// <summary>
        /// debug��忪��
        /// </summary>
        /// <param name="context"></param>
        public void OnDebugInfo(InputAction.CallbackContext context)
        {
            if (context.started)
            {
                DebuginfoInput = _debugInfoBroadButton.debuginfoInput = 1f;
                this.SendEvent(_debugInfoBroadButton);
            }
            if (context.canceled)
            {
                DebuginfoInput = _debugInfoBroadButton.debuginfoInput = 0f;
                this.SendEvent(_debugInfoBroadButton);
            }
        }
        /// <summary>
        /// ��Ϸ�ڲ˵���ť
        /// </summary>
        /// <param name="context"></param>
        public void OnGameMenu(InputAction.CallbackContext context)
        {
            if (context.started)
            {
                GameMenuInput = _gameMenuButton.gameMenuInput = 1f;
                this.SendEvent(_gameMenuButton);
            }
            if (context.canceled)
            {
                GameMenuInput = _gameMenuButton.gameMenuInput = 0f;
                this.SendEvent(_gameMenuButton);
            }
        }
        #endregion
    }
}